[src] Add [Un]SupportedSimulator attributes.#25347
Conversation
Add two attributes to specify whether an API is available in the simulator:
* [UnsupportedSimulator ("<platform>")]: API is not available.
* [SupportedSimulator ("<platform>[osversion]")]: API is available, optionally
only in the specified OS version or not.
If no attribute is found, then the API is available in the simulator.
Unlike the normal availability attributes, specifying simulator availability for
one platform does not mean anything for any other platforms.
There was a problem hiding this comment.
Pull request overview
This PR introduces two new attributes ([SupportedSimulator] / [UnsupportedSimulator]) to describe simulator-only availability for APIs, wires the logic into both the binding generator (bgen) and introspection tests, and replaces a number of simulator-specific skip-lists with attribute-driven behavior (notably for newer Metal/MetalFX/VideoToolbox APIs).
Changes:
- Added
SupportedSimulatorAttribute/UnsupportedSimulatorAttributetoObjCRuntime, and trimmed them during linking. - Updated bgen to emit simulator-availability attributes for iOS/tvOS only, with new bgen unit tests to validate emission behavior.
- Updated introspection tests to honor simulator-availability attributes, and annotated relevant Metal/MetalFX/VideoToolbox APIs as unsupported in iOS/tvOS simulators.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/introspection/ApiCtorInitTest.cs | Removes hardcoded simulator skip cases now handled via simulator-availability attributes. |
| tests/introspection/ApiBaseTest.cs | Extends skip logic to consider simulator availability (IsAvailableInSimulator). |
| tests/common/PlatformInfo.cs | Adds reflection-based evaluation of [SupportedSimulator] / [UnsupportedSimulator] during simulator runs. |
| tests/bgen/tests/simulator-availability-attributes.cs | Adds a dedicated bgen fixture file exercising simulator availability attributes. |
| tests/bgen/BGenTests.cs | Adds tests verifying simulator attributes are emitted for iOS/tvOS and not emitted for macOS/Mac Catalyst. |
| src/videotoolbox.cs | Marks specific new VideoToolbox APIs as unsupported on iOS/tvOS simulators. |
| src/TrimAttributes.LinkDescription.xml | Ensures simulator-availability attributes are removed by the linker (attribute-instance trimming). |
| src/ObjCRuntime/SupportedSimulatorAttribute.cs | Introduces the new public attributes in ObjCRuntime. |
| src/metalfx.cs | Marks MetalFX descriptor APIs as unsupported on iOS/tvOS simulators. |
| src/Metal/MTLEnums.cs | Marks selected Metal enums as unsupported on iOS/tvOS simulators. |
| src/metal.cs | Marks many Metal (incl. Metal 4) APIs as unsupported on iOS/tvOS simulators. |
| src/frameworks.sources | Adds the new attribute source file to the shared core sources list. |
| src/bgen/Generator.cs | Adds emission of simulator-availability attributes (filtered to current platform; ignored on Mac platforms). |
| src/bgen/Enums.cs | Ensures simulator-availability attributes are printed for enum extension generation as well. |
| src/bgen/bgen.csproj | Includes the new attribute definitions in the bgen build. |
| src/bgen/AttributeManager.cs | Teaches attribute loading to resolve the new attribute types. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/review |
|
✅ .NET for Apple Platforms PR Reviewer completed successfully! |
There was a problem hiding this comment.
Review Summary
This PR introduces two new attributes ([SupportedSimulator] and [UnsupportedSimulator]) to specify whether APIs are available in iOS/tvOS simulators. The implementation is well-structured and follows the repository's patterns.
✅ What's Good
- Clear architecture: The attributes are properly integrated into bgen, with filtering logic that only emits attributes relevant to the current platform
- Comprehensive testing: Includes bgen tests, introspection test integration, and proper handling in
PlatformInfo.IsAvailableInSimulator() - Proper trimming configuration: The attributes are correctly configured for removal during app trimming in
TrimAttributes.LinkDescription.xml - Consistent usage: Applied systematically to MLCompute, Metal, MetalFX, and VideoToolbox APIs that aren't available in simulators
- Test cleanup: Removes numerous simulator-specific workarounds from introspection tests now that the framework properly tracks simulator availability
📊 Issues Found
⚠️ 1 warning: Performance issue with string allocations inIsAvailableInSimulator()hot path- 💡 4 suggestions: Code duplication, error handling, documentation clarity, and immutability patterns
Verdict
No blocking issues. The warnings and suggestions are optional improvements that would enhance code quality but aren't required for merge.
CI status: Some test failures present (monotouch_tvos, xcframework, interdependent-binding-projects), but these appear unrelated to this change since the core simulator and introspection tests pass.
Generated by .NET for Apple Platforms PR Reviewer for issue #25347 · ● 875K
…rove docs - Extract IsSimulatorAvailabilityRelevantPlatform() helper in Generator.cs to reduce duplicated platform switch logic. - Use AsSpan() instead of Substring() in PlatformInfo.IsAvailableInSimulator to avoid string allocations in the hot path. - Throw InvalidOperationException on malformed version strings instead of silently continuing. - Improve XML doc for platformName param with format examples. - Make PlatformName properties init-only for immutability. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Adds ApiSimulatorAvailabilityTest which verifies that: - P/Invokes and [Field] properties marked with [UnsupportedSimulator] truly have unavailable native symbols in the simulator. - P/Invokes and [Field] properties NOT marked as unsupported don't have missing symbols (detecting cases where [UnsupportedSimulator] is needed). The test only runs in the simulator and is ignored on device/desktop. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/review |
|
✅ .NET for Apple Platforms PR Reviewer completed successfully! |
There was a problem hiding this comment.
Review Summary
✅ Clean implementation — This PR introduces simulator availability attributes with excellent attention to detail.
What's Good
- Complete feature implementation: Both
[SupportedSimulator]and[UnsupportedSimulator]attributes are properly designed with platform name + optional version support - Proper trimming configuration: Attributes correctly marked for trimming in
TrimAttributes.LinkDescription.xml - Platform-aware code generation: bgen correctly filters attributes to only emit those relevant to the current platform (iOS/tvOS get simulator attributes, macOS/Catalyst do not)
- Comprehensive test coverage:
- BGen unit tests verify attribute emission for iOS/tvOS and absence for Mac platforms
- Introspection tests validate P/Invoke and Field symbol availability at runtime
- Test helper
IsAvailableInSimulator()properly checks attributes with version constraints
- Consistent usage: Applied systematically across MLCompute, Metal, VideoToolbox, and MetalFX bindings
- Good documentation: XML docs clearly explain the semantics and the independence from standard availability attributes
Findings
- 💡 1 suggestion for nullable pattern consistency (see inline comment)
Recommendation
This is high-quality work from a senior maintainer. The single suggestion is optional and does not block merge. CI checks are still running — once green, this should be good to go.
Total: 1 suggestion
Generated by .NET for Apple Platforms PR Reviewer for issue #25347 · ● 1.1M
✅ [PR Build #fc0a48a] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #fc0a48a] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [PR Build #fc0a48a] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #fc0a48a] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 169 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Add two attributes to specify whether an API is available in the simulator:
only in the specified OS version or not.
If no attribute is found, then the API is available in the simulator.
Unlike the normal availability attributes, specifying simulator availability for
one platform does not mean anything for any other platforms.